//package com.example.s16_springsecurity.config;
//
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.core.annotation.Order;
//import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
//import org.springframework.security.config.annotation.web.builders.HttpSecurity;
//import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
//import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
//import org.springframework.security.crypto.password.NoOpPasswordEncoder;
//import org.springframework.security.crypto.password.PasswordEncoder;
//
//@Configuration
//public class MyWebSecurityConfig2 {
//
//
//    // 密码加密方式
//    @Bean
//    PasswordEncoder passwordEncoder() {
////        return NoOpPasswordEncoder.getInstance();// 密码不加密
//        return new BCryptPasswordEncoder(10); // 强hash加密 迭代次数
//    }
//
//    // 账号信息
//    @Autowired
//    protected void configure(AuthenticationManagerBuilder auth) throws Exception
//    {
//        auth.inMemoryAuthentication()
//                .withUser("root").password("$2a$10$vgdaP09TqJG3eIvNNaRAguGwZUBuHMfYUvMA0e.E55fX2bd9G6V5e").roles("ADMIN", "DBA")
//                .and()
//                .withUser("admin").password("$2a$10$vgdaP09TqJG3eIvNNaRAguGwZUBuHMfYUvMA0e.E55fX2bd9G6V5e").roles("ADMIN", "USER")
//                .and()
//                .withUser("zhangsan").password("$2a$10$vgdaP09TqJG3eIvNNaRAguGwZUBuHMfYUvMA0e.E55fX2bd9G6V5e").roles("USER");
//    }
//
//    // 管理员的配置信息
//    @Configuration
//    @Order(1)
//    public static class AdminSecurityConfig
//            extends WebSecurityConfigurerAdapter {
//        @Override
//        protected void configure(HttpSecurity http) throws Exception {
//            http.antMatcher("/admin/**").authorizeRequests()
//                    .anyRequest().hasRole("ADMIN");
//        }
//    }
//
//    // 其他用户的配置信息
//    @Configuration
//    public static class OtherSecurityConfig
//            extends WebSecurityConfigurerAdapter{
//        @Override
//        protected void configure(HttpSecurity http) throws Exception {
//            http.authorizeRequests()
//                    .anyRequest()
//                    .authenticated()
//                    .and()
//                    .formLogin()
//                    .loginProcessingUrl("/login")
//                    .permitAll()
//                    .and()
//                    .csrf()
//                    .disable();
//        }
//    }
//}
